package com.prolestar.web.controller.participation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.prolestar.common.annotation.Log;
import com.prolestar.common.core.controller.BaseController;
import com.prolestar.common.core.domain.AjaxResult;
import com.prolestar.common.core.page.TableDataInfo;
import com.prolestar.common.enums.BusinessType;
import com.prolestar.common.utils.poi.ExcelUtil;
import com.prolestar.participation.domain.PsParticipation;
import com.prolestar.participation.domain.SelectUrl;
import com.prolestar.participation.service.IPsParticipationService;
import com.prolestar.system.service.ISysConfigService;
import com.prolestar.util.MySetPage;

/**
 * 公众参与Controller
 * 
 * @author xuyp
 * @date 2022-11-21
 */
@RestController
@RequestMapping("/participation/participation")
public class PsParticipationController extends BaseController
{
    @Autowired
    private IPsParticipationService psParticipationService;

    @Autowired
    private ISysConfigService sysConfigService;

    /**
     * 查询公众参与列表
     */
    @PreAuthorize("@ss.hasPermi('participation:participation:list')")
    @GetMapping("/list")
    public TableDataInfo list(PsParticipation psParticipation)
    {
//        startPage();
        List<PsParticipation> list = psParticipationService.selectPsParticipationList(psParticipation);
//        return getDataTable(list);
        return MySetPage.mySetPage(list);
    }


    /**
     * 导出公众参与列表
     */
    @PreAuthorize("@ss.hasPermi('participation:participation:export')")
    @Log(title = "公众参与", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PsParticipation psParticipation)
    {
        List<PsParticipation> list = psParticipationService.selectPsParticipationList(psParticipation);
        ExcelUtil<PsParticipation> util = new ExcelUtil<PsParticipation>(PsParticipation.class);
        util.exportExcel(response, list, "公众参与数据");
    }

    /**
     * 获取公众参与详细信息
     */
    @PreAuthorize("@ss.hasPermi('participation:participation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(psParticipationService.selectPsParticipationById(id));
    }

    /**
     * 新增公众参与
     */
//    @PreAuthorize("@ss.hasPermi('participation:participation:add')")
    @Log(title = "公众参与", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PsParticipation psParticipation)
    {
        return toAjax(psParticipationService.insertPsParticipation(psParticipation));
    }

    /**
     * 修改公众参与
     */
    @PreAuthorize("@ss.hasPermi('participation:participation:edit')")
    @Log(title = "公众参与", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PsParticipation psParticipation)
    {
        return toAjax(psParticipationService.updatePsParticipation(psParticipation));
    }

    /**
     * 删除公众参与
     */
    @PreAuthorize("@ss.hasPermi('participation:participation:remove')")
    @Log(title = "公众参与", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(psParticipationService.deletePsParticipationByIds(ids));
    }

    /**
     * 服务器url
     * @return
     */
    @GetMapping("/selectUrl")
    public SelectUrl selectUrl(){
        SelectUrl selectUrl = psParticipationService.selectUrl();
         return selectUrl;
    }

    /**
     * 不采纳
     */
    @PostMapping("/accept")
    public AjaxResult accept(@RequestBody PsParticipation psParticipation){
        return psParticipationService.accept(psParticipation);
    }






}
